<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Connect to Remote Device</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="kvaser.gif"/></td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('page_example_c_kvrconnect.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Connect to Remote Device </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><b>samples\example\c\kvrConnect.c</b> </p><div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment">** This software is furnished as Redistributable under the Kvaser Software Licence</span></div><div class="line"><span class="comment">** https://www.kvaser.com/canlib-webhelp/page_license_and_copyright.html</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">** Description:</span></div><div class="line"><span class="comment">** This examples shows how to find a device on your network.</span></div><div class="line"><span class="comment">**/</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;stdio.h&gt;</span></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="canlib_8h.html">canlib.h</a>&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="kvrlib_8h.html">kvrlib.h</a>&quot;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#ifndef MIN</span></div><div class="line"><span class="preprocessor"># define MIN(a, b) (((a) &lt; (b)) ? (a) : (b))</span></div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"><span class="preprocessor">#ifndef MAX</span></div><div class="line"><span class="preprocessor"># define MAX(a, b) (((a) &gt; (b)) ? (a) : (b))</span></div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">char</span> password[64] = <span class="stringliteral">&quot;Hello World!&quot;</span>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">char</span> *getUsage (<span class="keywordtype">int</span> usage)</div><div class="line">{</div><div class="line">  <span class="keyword">static</span> <span class="keywordtype">char</span> *free    = <span class="stringliteral">&quot;FREE&quot;</span>;</div><div class="line">  <span class="keyword">static</span> <span class="keywordtype">char</span> *remote  = <span class="stringliteral">&quot;REMOTE&quot;</span>;</div><div class="line">  <span class="keyword">static</span> <span class="keywordtype">char</span> *usb     = <span class="stringliteral">&quot;USB&quot;</span>;</div><div class="line">  <span class="keyword">static</span> <span class="keywordtype">char</span> *config  = <span class="stringliteral">&quot;CONFIG&quot;</span>;</div><div class="line">  <span class="keyword">static</span> <span class="keywordtype">char</span> *unknown = <span class="stringliteral">&quot;UNKNOWN&quot;</span>;</div><div class="line"></div><div class="line">  <span class="keywordflow">switch</span> (usage) {</div><div class="line">    <span class="keywordflow">case</span> kvrDeviceUsage_FREE:   <span class="keywordflow">return</span> free;</div><div class="line">    <span class="keywordflow">case</span> kvrDeviceUsage_REMOTE: <span class="keywordflow">return</span> remote;</div><div class="line">    <span class="keywordflow">case</span> kvrDeviceUsage_USB:    <span class="keywordflow">return</span> usb;</div><div class="line">    <span class="keywordflow">case</span> kvrDeviceUsage_CONFIG: <span class="keywordflow">return</span> config;</div><div class="line">    <span class="keywordflow">default</span>:              <span class="keywordflow">return</span> unknown;</div><div class="line">  }</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> isUsedByMe (kvrDeviceInfo *di)</div><div class="line">{</div><div class="line">  <span class="keywordtype">int</span> i;</div><div class="line">  <span class="keywordtype">int</span> channel_count;</div><div class="line">  <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7">canStatus</a> status;</div><div class="line">  <span class="keywordtype">char</span> ean[8];</div><div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> serial = 0;</div><div class="line"></div><div class="line">  <a class="code" href="group__can__general.html#gaff1ec1d3416d3bdd56336a7b9ac008b1">canInitializeLibrary</a>();</div><div class="line"></div><div class="line">  status = <a class="code" href="group__can__general.html#ga65169ca633cd30aa92b8a80e28a5378b">canGetNumberOfChannels</a>(&amp;channel_count);</div><div class="line">  <span class="keywordflow">if</span> (status != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a>) {</div><div class="line">    printf(<span class="stringliteral">&quot;ERROR: canGetNumberOfChannels failed %d\n&quot;</span>, status);</div><div class="line">    <span class="keywordflow">return</span> -1;</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">for</span> (i = 0; (status == <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a>) &amp;&amp; (i &lt; channel_count); i++) {</div><div class="line">    <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> ean_hi = 0;</div><div class="line">    <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> ean_lo = 0;</div><div class="line"></div><div class="line">    status = <a class="code" href="group__can__general.html#gab9552d1a588b0dbc144b097acba017b2">canGetChannelData</a>(i, <a class="code" href="canlib_8h.html#a9062beaa59d9787667bac6cbbc6b4e20">canCHANNELDATA_CARD_UPC_NO</a>, ean, <span class="keyword">sizeof</span>(ean));</div><div class="line">    <span class="keywordflow">if</span> (status != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a>) {</div><div class="line">      printf(<span class="stringliteral">&quot;ERROR: canCHANNELDATA_CARD_UPC_NO failed: %d\n&quot;</span>, status);</div><div class="line">      <span class="keywordflow">return</span> -1;</div><div class="line">    }</div><div class="line">    ean_hi  = (ean[7] &lt;&lt; 24) &amp; 0xFF000000;</div><div class="line">    ean_hi += (ean[6] &lt;&lt; 16) &amp; 0x00FF0000;</div><div class="line">    ean_hi += (ean[5] &lt;&lt; 8)  &amp; 0x0000FF00;</div><div class="line">    ean_hi += ean[4]         &amp; 0x000000FF;</div><div class="line">    ean_lo  = (ean[3] &lt;&lt; 24) &amp; 0xFF000000;</div><div class="line">    ean_lo += (ean[2] &lt;&lt; 16) &amp; 0x00FF0000;</div><div class="line">    ean_lo += (ean[1] &lt;&lt; 8)  &amp; 0x0000FF00;</div><div class="line">    ean_lo += ean[0]         &amp; 0x000000FF;</div><div class="line"></div><div class="line">    status = <a class="code" href="group__can__general.html#gab9552d1a588b0dbc144b097acba017b2">canGetChannelData</a>(i, <a class="code" href="canlib_8h.html#a8b3b4903a766565c95afd7c90f76d994">canCHANNELDATA_CARD_SERIAL_NO</a>,</div><div class="line">                               &amp;serial, <span class="keyword">sizeof</span>(serial));</div><div class="line">    <span class="keywordflow">if</span> (status != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a>) {</div><div class="line">      printf(<span class="stringliteral">&quot;ERROR: canCHANNELDATA_CARD_SERIAL_NO failed: %d\n&quot;</span>, status);</div><div class="line">      <span class="keywordflow">return</span> -1;</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> ((di-&gt;ean_lo == ean_lo) &amp;&amp; (di-&gt;ean_hi == ean_hi) &amp;&amp;</div><div class="line">        (di-&gt;ser_no == serial))</div><div class="line">    {</div><div class="line">      <span class="keywordflow">return</span> 1;</div><div class="line">    }</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">//------------------------------------------------------------------------------</span></div><div class="line"><span class="comment">// Dump information</span></div><div class="line"><span class="comment">//------------------------------------------------------------------------------</span></div><div class="line"><span class="keywordtype">void</span> dumpDeviceInfo (kvrDeviceInfo *di)</div><div class="line">{</div><div class="line">  <span class="keywordtype">char</span>      service_text[256];</div><div class="line">  kvrStatus status;</div><div class="line">  <span class="keywordtype">char</span>      addr_buf[22];</div><div class="line">  int32_t   service_state;</div><div class="line">  int32_t   service_sub_state;</div><div class="line"></div><div class="line">  printf(<span class="stringliteral">&quot;--------------------------------------------------------------------------\n&quot;</span>);</div><div class="line">  printf(<span class="stringliteral">&quot;Device information\n&quot;</span>);</div><div class="line">  printf(<span class="stringliteral">&quot;EAN:         %x%x\n&quot;</span>, di-&gt;ean_hi, di-&gt;ean_lo);</div><div class="line">  printf(<span class="stringliteral">&quot;FW version:  %d.%d.%d\n&quot;</span>,</div><div class="line">         di-&gt;fw_major_ver, di-&gt;fw_minor_ver, di-&gt;fw_build_ver);</div><div class="line">  printf(<span class="stringliteral">&quot;Serial:      %ld\n&quot;</span>, di-&gt;ser_no);</div><div class="line">  printf(<span class="stringliteral">&quot;Name:        %s\n&quot;</span>, di-&gt;name);</div><div class="line">  printf(<span class="stringliteral">&quot;Host name:   %s\n&quot;</span>, di-&gt;host_name);</div><div class="line">  printf(<span class="stringliteral">&quot;Password:    &quot;</span>);</div><div class="line">  <span class="keywordflow">if</span> (!di-&gt;accessibility_pwd[0]) {</div><div class="line">    printf(<span class="stringliteral">&quot;None\n&quot;</span>);</div><div class="line">  } <span class="keywordflow">else</span> {</div><div class="line">    <span class="keywordtype">int</span> i;</div><div class="line">    <span class="keywordflow">for</span>(i = 0; i &lt; MIN(32, di-&gt;accessibility_pwd[0]); i++) {</div><div class="line">      <span class="keywordflow">if</span> (i == 16) {</div><div class="line">       printf(<span class="stringliteral">&quot;\n             &quot;</span>);</div><div class="line">      }</div><div class="line">      printf(<span class="stringliteral">&quot;%02x &quot;</span>, (uint8_t)di-&gt;accessibility_pwd[i + 3]);</div><div class="line">    }</div><div class="line">    printf(<span class="stringliteral">&quot; (%02x%02x)\n&quot;</span>,</div><div class="line">           (uint8_t)di-&gt;accessibility_pwd[2], (uint8_t)di-&gt;accessibility_pwd[1]);</div><div class="line">  }</div><div class="line">  kvrStringFromAddress(addr_buf, <span class="keyword">sizeof</span>(addr_buf), &amp;di-&gt;device_address);</div><div class="line">  printf(<span class="stringliteral">&quot;IP:          %s\n&quot;</span>, addr_buf);</div><div class="line">  kvrStringFromAddress(addr_buf, <span class="keyword">sizeof</span>(addr_buf), &amp;di-&gt;client_address);</div><div class="line">  printf(<span class="stringliteral">&quot;Client IP:   %s\n&quot;</span>, addr_buf);</div><div class="line">  printf(<span class="stringliteral">&quot;Usage:       %s&quot;</span>, getUsage(di-&gt;usage));</div><div class="line">  <span class="keywordflow">if</span> ((di-&gt;usage != kvrDeviceUsage_FREE) &amp;&amp; (isUsedByMe(di) &gt; 0)) {</div><div class="line">    printf(<span class="stringliteral">&quot; - Used by Me!\n&quot;</span>);</div><div class="line">  } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (di-&gt;usage != kvrDeviceUsage_FREE &amp;&amp; di-&gt;usage != kvrDeviceUsage_UNKNOWN) {</div><div class="line">    printf(<span class="stringliteral">&quot; - Used by other!\n&quot;</span>);</div><div class="line">  } <span class="keywordflow">else</span> {</div><div class="line">    printf(<span class="stringliteral">&quot;\n&quot;</span>);</div><div class="line">  }</div><div class="line">  printf(<span class="stringliteral">&quot;Alive:       %s\n&quot;</span>,</div><div class="line">         ((di-&gt;availability &amp; kvrAvailability_FOUND_BY_SCAN) ? <span class="stringliteral">&quot;Yes&quot;</span> : <span class="stringliteral">&quot;No&quot;</span>));</div><div class="line">  printf(<span class="stringliteral">&quot;Stored:      %s\n&quot;</span>, ((di-&gt;availability &amp; kvrAvailability_STORED) ? <span class="stringliteral">&quot;Yes&quot;</span> : <span class="stringliteral">&quot;No&quot;</span>));</div><div class="line"></div><div class="line">  <span class="comment">// Ask service for status service_text</span></div><div class="line">  status = kvrDeviceGetServiceStatusText(di, service_text,</div><div class="line">                                         <span class="keyword">sizeof</span>(service_text));</div><div class="line">  <span class="keywordflow">if</span> (status != kvrOK) {</div><div class="line">    <span class="keywordtype">char</span>      buf[256];</div><div class="line">    kvrGetErrorText(status, buf, <span class="keyword">sizeof</span>(buf));</div><div class="line">    printf(<span class="stringliteral">&quot;Service:     FAILED - %s\n&quot;</span>, buf);</div><div class="line">  } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(service_text, <span class="stringliteral">&quot;Service: &quot;</span>, strlen(<span class="stringliteral">&quot;Service: &quot;</span>)) == 0) {</div><div class="line">    printf(<span class="stringliteral">&quot;Service:     %s\n&quot;</span>, &amp;service_text[strlen(<span class="stringliteral">&quot;Service: &quot;</span>)]);</div><div class="line">  } <span class="keywordflow">else</span> {</div><div class="line">    printf(<span class="stringliteral">&quot;%s\n&quot;</span>, service_text);</div><div class="line">  }</div><div class="line"></div><div class="line">  status = kvrDeviceGetServiceStatus(di, &amp;service_state, &amp;service_sub_state);</div><div class="line">  <span class="keywordflow">if</span> (status == kvrOK) {</div><div class="line">    printf(<span class="stringliteral">&quot;service_state: %d.%d\n&quot;</span>, service_state, service_sub_state);</div><div class="line">  } <span class="keywordflow">else</span> {</div><div class="line">    printf(<span class="stringliteral">&quot;service_state: unknown\n&quot;</span>);</div><div class="line">  }</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">//------------------------------------------------------------------------------</span></div><div class="line"><span class="comment">// Broadcast for all devices of a specific EAN and add them to the device list</span></div><div class="line"><span class="comment">// Note that the device list could have some devices in it already.</span></div><div class="line"><span class="comment">//------------------------------------------------------------------------------</span></div><div class="line">kvrStatus setupBroadcast (kvrDiscoveryHandle handle)</div><div class="line">{</div><div class="line">  <span class="keywordtype">char</span>        buf[256];</div><div class="line">  kvrStatus   status;</div><div class="line">  kvrAddress  addr_list[10];</div><div class="line">  uint32_t    no_addrs        = 0;</div><div class="line">  uint32_t    i;</div><div class="line"></div><div class="line">  status = kvrDiscoveryGetDefaultAddresses(addr_list,</div><div class="line">                                           <span class="keyword">sizeof</span>(addr_list)/<span class="keyword">sizeof</span>(kvrAddress),</div><div class="line">                                           &amp;no_addrs,</div><div class="line">                                           kvrAddressTypeFlag_ALL);</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (status != kvrOK) {</div><div class="line">    kvrGetErrorText(status, buf, <span class="keyword">sizeof</span>(buf));</div><div class="line">    printf(<span class="stringliteral">&quot;kvrDiscoveryGetDefaultAddresses() FAILED - %s\n&quot;</span>, buf);</div><div class="line">    <span class="keywordflow">return</span> status;</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (no_addrs &lt; <span class="keyword">sizeof</span>(addr_list)/<span class="keyword">sizeof</span>(kvrAddress)) {</div><div class="line">    status = kvrAddressFromString(kvrAddressType_IPV4, &amp;addr_list[no_addrs], <span class="stringliteral">&quot;10.0.3.66&quot;</span>);</div><div class="line">    <span class="keywordflow">if</span> (status != kvrOK) {</div><div class="line">      printf(<span class="stringliteral">&quot;ERROR: kvrAddressFromString(%d, 10.0.3.1) failed\n&quot;</span>,no_addrs);</div><div class="line">    } <span class="keywordflow">else</span> {</div><div class="line">      no_addrs++;</div><div class="line">    }</div><div class="line">  } <span class="keywordflow">else</span> {</div><div class="line">    printf(<span class="stringliteral">&quot;NOTE: We don&#39;t have room for all devices in addr_list[%zu].\n&quot;</span>,</div><div class="line">           <span class="keyword">sizeof</span>(addr_list)/<span class="keyword">sizeof</span>(kvrAddress));</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">for</span> (i=0; i &lt; no_addrs; i++) {</div><div class="line">    status = kvrStringFromAddress(buf, <span class="keyword">sizeof</span>(buf), &amp;addr_list[i]);</div><div class="line">    printf(<span class="stringliteral">&quot;Looking for device using: %s\n&quot;</span>, buf);</div><div class="line">  }</div><div class="line"></div><div class="line">  status = kvrDiscoverySetAddresses(handle, addr_list, no_addrs);</div><div class="line">  <span class="keywordflow">if</span> (status != kvrOK) {</div><div class="line">    kvrGetErrorText(status, buf, <span class="keyword">sizeof</span>(buf));</div><div class="line">    printf(<span class="stringliteral">&quot;kvrDiscoverySetAddresses() FAILED - %s\n&quot;</span>, buf);</div><div class="line">    <span class="keywordflow">return</span> status;</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">return</span> status;</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">//------------------------------------------------------------------------------</span></div><div class="line"><span class="comment">// Discover devices and add them to device list</span></div><div class="line"><span class="comment">//------------------------------------------------------------------------------</span></div><div class="line">kvrStatus discoverDevices (kvrDiscoveryHandle handle)</div><div class="line">{</div><div class="line">  kvrStatus status;</div><div class="line">  kvrDeviceInfo device_info[64];</div><div class="line">  <span class="keywordtype">int</span> devices;</div><div class="line">  uint32_t delay_ms = 500;</div><div class="line">  uint32_t timeout_ms = 300;</div><div class="line">  <span class="keywordtype">char</span>        buf[256];</div><div class="line"></div><div class="line">  status = kvrDiscoveryStart(handle, delay_ms, timeout_ms);</div><div class="line">  <span class="keywordflow">if</span> (status != kvrOK) {</div><div class="line">    kvrGetErrorText(status, buf, <span class="keyword">sizeof</span>(buf));</div><div class="line">    printf(<span class="stringliteral">&quot;kvrDiscoveryStart() FAILED - %s\n&quot;</span>, buf);</div><div class="line">    <span class="keywordflow">return</span> status;</div><div class="line">  }</div><div class="line"></div><div class="line">  devices = 0;</div><div class="line">  <span class="keywordflow">while</span> (status == kvrOK) {</div><div class="line">    status = kvrDiscoveryGetResults(handle, &amp;device_info[devices]);</div><div class="line">    <span class="keywordflow">if</span> (status == kvrOK) {</div><div class="line">      dumpDeviceInfo(&amp;device_info[devices]);</div><div class="line">      <span class="comment">// Add some data and request store</span></div><div class="line">      <span class="keywordflow">if</span> (kvrDiscoverySetPassword(&amp;device_info[devices], password) != kvrOK) {</div><div class="line">        printf(<span class="stringliteral">&quot;Unable to set password: %s (%zu)\n&quot;</span>, password, strlen(password));</div><div class="line">      }</div><div class="line">      <span class="comment">// Here we can decide to connect to the device</span></div><div class="line">      <span class="comment">//device_info[devices].request_connection = 1;</span></div><div class="line">      devices++;</div><div class="line">    } <span class="keywordflow">else</span> {</div><div class="line">      <span class="keywordflow">if</span> (status != kvrERR_BLANK) {</div><div class="line">        printf(<span class="stringliteral">&quot;kvrDiscoveryGetResults() failed %d\n&quot;</span>, status );</div><div class="line">      }</div><div class="line">    }</div><div class="line">  }</div><div class="line"></div><div class="line">  status = kvrDiscoveryStoreDevices(device_info, devices);</div><div class="line">  <span class="keywordflow">if</span> (status != kvrOK) {</div><div class="line">    kvrGetErrorText(status, buf, <span class="keyword">sizeof</span>(buf));</div><div class="line">    printf(<span class="stringliteral">&quot;Device store failed: %s\n&quot;</span>, buf);</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">return</span> kvrOK;</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">//------------------------------------------------------------------------------</span></div><div class="line"><span class="comment">// Setup a number of WLAN devices for future CANLIB use</span></div><div class="line"><span class="comment">//------------------------------------------------------------------------------</span></div><div class="line"><span class="keywordtype">int</span> main (<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])</div><div class="line">{</div><div class="line">  kvrStatus status;</div><div class="line">  kvrDiscoveryHandle handle;</div><div class="line">  <span class="keywordtype">char</span>        buf[256];</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (argc &gt; 1) {</div><div class="line">    strcpy(password, argv[1]);</div><div class="line">  }</div><div class="line"></div><div class="line">  kvrInitializeLibrary();</div><div class="line"></div><div class="line">  status = kvrDiscoveryOpen(&amp;handle);</div><div class="line">  <span class="keywordflow">if</span> (status != kvrOK) {</div><div class="line">    kvrGetErrorText(status, buf, <span class="keyword">sizeof</span>(buf));</div><div class="line">    printf(<span class="stringliteral">&quot;kvrDiscoveryOpen() FAILED - %s\n&quot;</span>, buf);</div><div class="line">    <span class="keywordflow">return</span> status;</div><div class="line">  }</div><div class="line"></div><div class="line">  status = setupBroadcast(handle);</div><div class="line">  <span class="keywordflow">if</span> (status != kvrOK) {</div><div class="line">    kvrGetErrorText(status, buf, <span class="keyword">sizeof</span>(buf));</div><div class="line">    printf(<span class="stringliteral">&quot;setupBroadcast() FAILED - %s\n&quot;</span>, buf);</div><div class="line">    <span class="keywordflow">return</span> status;</div><div class="line">  }</div><div class="line">  status = discoverDevices(handle);</div><div class="line">  <span class="keywordflow">if</span> (status != kvrOK) {</div><div class="line">    kvrGetErrorText(status, buf, <span class="keyword">sizeof</span>(buf));</div><div class="line">    printf(<span class="stringliteral">&quot;discoverDevices() FAILED - %s\n&quot;</span>, buf);</div><div class="line">    <span class="keywordflow">return</span> status;</div><div class="line">  }</div><div class="line"></div><div class="line">  kvrDiscoveryClose(handle);</div><div class="line">  kvrUnloadLibrary();</div><div class="line"></div><div class="line">  <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div></div><!-- fragment --> </div></div><!-- contents -->
</div><!-- doc-content -->
<!-- HTML footer for doxygen 1.8.13-->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="page_kvrlib.html">Remote Device API (kvrlib)</a></li><li class="navelem"><a class="el" href="page_user_guide_kvrlib_samples.html">Sample Programs (kvrlib)</a></li>
    <li class="footer"> (canlib 5.38) Tue Feb 15 2022</li>
  </ul>
</div>
</body>
</html>
